<?php

session_start();

$user=$_SESSION['user'];


$status=$_POST['status'];


//set the values neccessary to connect to the database
$host="localhost";
$username="root";
$password="";
$db="assessmentdb";

//create the connection to the database
$connection=mysql_connect($host, $username, $password);

//select my database
$mysel=mysql_select_db($db);
echo "<h1> Query based on assessment status</h1>";

if($status =="completed")
{
$check= "select * from assessment where username =\"$user\" and status = 'completed'";
$result=mysql_query($check, $connection);
echo "<p>You are currently viewing all assessments that are completed</p>";

echo "<table border='2'>";
echo "<tr>";
echo "<th>";
echo "Username";
echo "</th>"; 
echo "<th>";
echo "Assessment";
echo "</th>";
echo "<th>";
echo "Due Date";
echo "</th>";
echo "<th>";
echo "Date Completed";
echo "</th>";
echo "<th>";
echo "Description";
echo "</th>";
echo "<th>";
echo "Status";
echo "</th>";
echo "</tr>";


while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>";
echo $field2= $row['username'];
echo "</td>";
echo "<td>";
echo $field3=$row['assessment'];
echo "</td>";
echo "<td>";
echo $field4=$row['duedate'];
echo "</td>";
echo "<td>";
echo $field5=$row['datecompleted'];
echo "</td>";
echo "<td>";
echo $field6=$row['description'];
echo "</td>";
echo "<td>";
echo $field7=$row['status'];
echo "</td>";
echo "</tr>";

}

echo "</table>";

}
elseif($status == "not completed")
{
$check= "select * from assessment where username =\"$user\" and status ='not completed'";
$result=mysql_query($check, $connection);

echo "<p>You are currently viewing all assessment that are not completed</p>";

echo "<table border='2'>";
echo "<tr>";
echo "<th>";
echo "Username";
echo "</th>"; 
echo "<th>";
echo "Assessment";
echo "</th>";
echo "<th>";
echo "Due Date";
echo"</th>";
echo "<th>";
echo "Date Completed";
echo "</th>";
echo"<th>";
echo"Description";
echo"</th>";
echo"</tr>";


while($row=mysql_fetch_array($result))
{
echo"<tr>";
echo"<td>";
echo $field2= $row['username'];
echo "</td>";
echo "<td>";
echo $field3=$row['assessment'];
echo "</td>";
echo "<td>";
echo $field4=$row['duedate'];
echo "</td>";
echo "<td>";
echo $field5=$row['datecompleted'];
echo "</td>";
echo "<td>";
echo $field6=$row['description'];
echo "</td>";
echo "<td>";
echo $field7=$row['status'];
echo "</td>";
echo "</tr>";

}

echo "</table>";

}
else
{

header("location:editassessment.php");
}

?>